package com.example.app3_1;

// HomeViewModel.java
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import java.util.ArrayList;
import java.util.List;

public class HomeViewModel extends ViewModel {
    private MutableLiveData<List<Item>> items = new MutableLiveData<>();

    public HomeViewModel() {
        loadItems();
    }

    public LiveData<List<Item>> getItems() {
        return items;
    }

    public void loadItems() {
        // 模拟数据加载
        List<Item> itemList = new ArrayList<>();
        itemList.add(new Item("标题1", "描述1", ""));
        itemList.add(new Item("标题2", "描述2", ""));
        itemList.add(new Item("标题3", "描述3", ""));
        itemList.add(new Item("标题4", "描述4", ""));
        itemList.add(new Item("标题5", "描述5", ""));

        items.setValue(itemList);
    }

    public void refreshItems() {
        // 模拟刷新数据
        loadItems();
    }
}
